#[derive(Debug)]
enum Direction {
    East,
    West,
    North,
    South,
}

#[derive(Debug)]
enum UsState {
    Alabama,
    Alaska,
}
enum Coin {
    Penny,
    Nickel,
    Dime,
    Quarter(UsState),
}

struct Point {
    x: i32,
    y: i32,
    // z: i32,
}

fn value_in_cents(coin: Coin) -> u8 {
    match coin {
        Coin::Penny => 1,
        Coin::Nickel => 5,
        Coin::Dime => 10,
        Coin::Quarter(state) => {
            println!("State quarter from {:?}!", state);
            25
        }
    }
}

fn main() {
    // let dire = Direction::South;
    // match dire {
    //     Direction::East => println!("East"),
    //     // x|y 类似逻辑运算符 或,表示两种情况都可以匹配
    //     Direction::North | Direction::South => {
    //         println!("South or North");
    //     }
    //     // 其他情况 match 其实和switch很像
    //     _ => println!("West"),
    // }

    // let c1 = Coin::Quarter(UsState::Alabama);
    // let c3 = Coin::Quarter(UsState::Alaska);
    // let c2 = Coin::Penny;
    // println!("{}", value_in_cents(c1));
    // println!("{}", value_in_cents(c2));
    // println!("{}", value_in_cents(c3));

    // let v = Some(3u8);
    // if let Some(3) = v {
    //     println!("three");
    // }

    // // Vec是动态数组
    // let mut stack = Vec::new();

    // // 向数组尾部插入元素
    // stack.push(1);
    // stack.push(2);
    // stack.push(3);

    // // stack.pop从数组尾部弹出元素
    // while let Some(top) = stack.pop() {
    //     println!("{}", top);
    // }

    // let x = 5;
    // match x {
    //     // 范围匹配
    //     1..=5 => println!("between 1 and 5"),
    //     _ => println!("out of range 1 and 5"),
    // }

    // // 解构结构体
    // let p = Point { x: 0, y: 7, z:5};

    // let Point { x: a, y: b, z:_} = p;
    // assert_eq!(0, a);
    // assert_eq!(7, b);

    // println!("a:{},b:{}", a, b);

    let p = Point { x: 0, y: 7 };

    match p {
        Point { x, y: 0 } => println!("On the x axis at {}", x),
        Point { x: 0, y } => println!("On the y axis at {}", y),
        Point { x, y } => println!("On neither axis: ({}, {})", x, y),
    }
}
